<template>
  <!-- 人员类型新增 -->
  <el-dialog v-dialogDrag :title="dialogTitle" class="dialogStyleMiddle" :visible.sync="dialogVisible">
    <el-form ref="form" :model="formData" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="合同名称" prop="contractName">
            <el-input v-model="formData.contractName" readonly size="medium" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建设单位" prop="construction">
            <el-input v-model="formData.construction" readonly size="medium" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同类型" prop="contractType">
            <el-input v-model="formData.contractType" readonly size="medium" />
            <!--            <el-select :value="formData.contractType" style="width:100%" size="medium" placeholder="" readonly>-->
            <!--              <el-option-->
            <!--                v-for="item in contractType"-->
            <!--                :key="item.value"-->
            <!--                :label="item.label"-->
            <!--                :value="item.value"-->
            <!--              />-->
            <!--            </el-select>-->
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同工期" prop="contractDuration">
            <el-input v-model="formData.contractDuration" readonly size="medium">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同单价" prop="contractPrice">
            <el-input v-model="formData.contractPrice" readonly size="medium">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同总金额" prop="contractAmount">
            <el-input v-model="formData.contractAmount" readonly size="medium">
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="钻孔总数" prop="drillingCount">
            <el-input v-model="formData.drillingCount" readonly size="medium">
              <template slot="append">个</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="钻孔总米" prop="drillMember">
            <el-input v-model="formData.drillMember" readonly size="medium">
              <template slot="append">m</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最小深度" prop="minScope">
            <el-input v-model="formData.minScope" readonly size="medium" placeholder="">
              <template slot="append"><el-button />m</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最大深度" prop="maxScope">
            <el-input v-model="formData.maxScope" readonly size="medium" placeholder="">
              <template slot="append"><el-button />m</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="合同附件" prop="appFiles">
            <FileUplode
              ref="fileUplode"
              :edit-file-list="conractFileList"
              :read-only="true"
              @getFileList="getContractFile"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!--    <span slot="footer" class="dialog-footer">-->
    <!--      <el-button size="medium" @click="cancel">取 消</el-button>-->
    <!--      <el-button size="medium" type="primary" @click="submitForm">保 存</el-button>-->
    <!--    </span>-->
  </el-dialog>
</template>

<script>
// 上传文件
import FileUplode from '@/components/Upload/FileUplode'
import { detailContract } from '@/api/projectManage/project/proContract'
export default {
  name: 'DetailDialog',
  components: {
    FileUplode
  },
  data() {
    return {
      // 合同类型
      contractType: [
        {
          value: '0',
          label: '补充合同'
        },
        {
          value: '1',
          label: '原合同'
        }
      ],
      /* 新增 start */
      btnDisabled: false,
      dialogTitle: '', // 对话框是否弹出显示
      dialogVisible: false, // 对话框是否弹出显示
      conractFileList: [], // 合同附件
      formData: {
        id: '',
        proId: '', // 项目id
        contractName: '', // 合同名称
        construction: '', // 建设单位
        contractPrice: '', // 合同单价
        contractDuration: '', // 合同工期
        contractType: '', // 合同合同类型
        contractAmount: '', // 合同总金额
        drillingCount: '', // 钻孔总个数
        drillMember: '',
        appFiles: ''
      }
      /* 新增 end */
    }
  },
  computed: {
    contractAmount() {
      return contractAmount => this.divideMoney(contractAmount, 6)
    }
  },
  methods: {
    handleAdd(title, id) {
      this.dialogVisible = true
      this.dialogTitle = title
      // 重置表单
      this.emptyForm()
      if (id) {
        this.getDetailById(id)
      }
    },
    // 获取详情
    async getDetailById(id) {
      const { data } = await detailContract(id)
      if (data) {
        this.formData = { ...data }
        this.formData.contractAmount = this.divideMoney(data.contractAmount, 6, true)
        this.formData.contractPrice = this.divideMoney(data.contractPrice, 2)
        this.formData.contractType = this.contractType.filter(item => item.value === data.contractType)[0].label
        if (data.appFiles && data.appFiles.length > 0) {
          this.conractFileList = data.appFiles
        }
      }
    },
    // 弹框取消按钮
    cancel() {
      this.dialogVisible = false
      this.btnDisabled = false
    },
    // 保存
    submitForm() {
      this.cancel()
    },
    // 清空弹出
    emptyForm() {
      this.resetForm('form')
      this.formData.id = ''
      this.conractFileList = []
    },
    // 获取合同附件
    getContractFile(fileList, deleteFileIds) {
      this.formData.appFiles = fileList
      this.formData.fileDelete = deleteFileIds
    }
  }
}
</script>

